From 2eeff1eed6bd0bebcf8f1ade535317147a0e9ca9 Mon Sep 17 00:00:00 2001 From: Paolo Borelli Date: Sun, 15 Jun 2014 18:11:15 +0200 Subject: [PATCH] Add a TextView reftests checking border-windows TextView border windows are internal windows used to draw on the gutter of the textview (e.g. line numbers). The test uses the gmodule hook to programmatically draw on the border-windows at each side of the textview and compares the result with 3x3 grid of labels. --- testsuite/reftests/Makefile.am | 4 + testsuite/reftests/textview-border-windows.c | 75 +++++++++++++++++++ .../reftests/textview-border-windows.css | 21 ++++++ .../reftests/textview-border-windows.ref.ui | 74 ++++++++++++++++++ testsuite/reftests/textview-border-windows.ui | 20 +++++ 5 files changed, 194 insertions(+) create mode 100644 testsuite/reftests/textview-border-windows.c create mode 100644 testsuite/reftests/textview-border-windows.css create mode 100644 testsuite/reftests/textview-border-windows.ref.ui create mode 100644 testsuite/reftests/textview-border-windows.ui diff --git a/testsuite/reftests/Makefile.am b/testsuite/reftests/Makefile.am index d3842e5081..7e296a696d 100644 --- a/testsuite/reftests/Makefile.am +++ b/testsuite/reftests/Makefile.am @@ -328,6 +328,9 @@ testdata = \ symbolic-icon-translucent-color.css \ symbolic-icon-translucent-color.ref.ui \ symbolic-icon-translucent-color.ui \ + textview-border-windows.css \ + textview-border-windows.ref.ui \ + textview-border-windows.ui \ textview-margins.css \ textview-margins.ref.ui \ textview-margins.ui \ @@ -372,6 +375,7 @@ libreftest_la_LIBADD = $(gtk_reftest_LDADD) libreftest_la_SOURCES = \ set-default-direction.c \ expand-expander.c \ + textview-border-windows.c \ $(NULL) substitutions = \ diff --git a/testsuite/reftests/textview-border-windows.c b/testsuite/reftests/textview-border-windows.c new file mode 100644 index 0000000000..502b18b06d --- /dev/null +++ b/testsuite/reftests/textview-border-windows.c @@ -0,0 +1,75 @@ +/* + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library. If not, see . + */ + +#include "config.h" + +#include + +static void +paint_border (GtkTextView *text_view, + cairo_t *cr, + GtkTextWindowType type, + GtkStyleContext *context, + const char *class) +{ + GdkWindow *window; + + window = gtk_text_view_get_window (text_view, type); + + if (window != NULL && + gtk_cairo_should_draw_window (cr, window)) + { + gint w, h; + + gtk_style_context_save (context); + gtk_style_context_add_class (context, class); + + w = gdk_window_get_width (window); + h = gdk_window_get_height (window); + + gtk_cairo_transform_to_window (cr, GTK_WIDGET (text_view), window); + + cairo_save (cr); + gtk_render_background (context, cr, 0, 0, w, h); + cairo_restore (cr); + + gtk_style_context_restore (context); + } +} + +G_MODULE_EXPORT gboolean +paint_border_windows (GtkTextView *text_view, + cairo_t *cr) +{ + GtkStyleContext *context; + + context = gtk_widget_get_style_context (GTK_WIDGET (text_view)); + + paint_border (text_view, cr, GTK_TEXT_WINDOW_LEFT, context, "left"); + paint_border (text_view, cr, GTK_TEXT_WINDOW_RIGHT, context, "right"); + paint_border (text_view, cr, GTK_TEXT_WINDOW_TOP, context, "top"); + paint_border (text_view, cr, GTK_TEXT_WINDOW_BOTTOM, context, "bottom"); + + return FALSE; +} + +G_MODULE_EXPORT void +add_border_windows (GtkTextView *text_view) +{ + gtk_text_view_set_border_window_size (text_view, GTK_TEXT_WINDOW_LEFT, 30); + gtk_text_view_set_border_window_size (text_view, GTK_TEXT_WINDOW_RIGHT, 30); + gtk_text_view_set_border_window_size (text_view, GTK_TEXT_WINDOW_TOP, 30); + gtk_text_view_set_border_window_size (text_view, GTK_TEXT_WINDOW_BOTTOM, 30); +} diff --git a/testsuite/reftests/textview-border-windows.css b/testsuite/reftests/textview-border-windows.css new file mode 100644 index 0000000000..79eb97103e --- /dev/null +++ b/testsuite/reftests/textview-border-windows.css @@ -0,0 +1,21 @@ +@import "reset-to-defaults.css"; + +.top, +#label_n { + background-color: blue; +} + +.left, +#label_w { + background-color: green; +} + +.right, +#label_e { + background-color: yellow; +} + +.bottom, +#label_s { + background-color: red; +} diff --git a/testsuite/reftests/textview-border-windows.ref.ui b/testsuite/reftests/textview-border-windows.ref.ui new file mode 100644 index 0000000000..642feb1694 --- /dev/null +++ b/testsuite/reftests/textview-border-windows.ref.ui @@ -0,0 +1,74 @@ + + + + + + False + popup + + + True + False + + + 100 + 100 + True + + + 1 + 1 + + + + + label_n + 30 + True + False + + + 1 + 0 + + + + + label_w + 30 + True + False + + + 0 + 1 + + + + + label_e + 30 + True + False + + + 2 + 1 + + + + + label_s + 30 + True + False + + + 1 + 2 + + + + + + diff --git a/testsuite/reftests/textview-border-windows.ui b/testsuite/reftests/textview-border-windows.ui new file mode 100644 index 0000000000..7aa6b22fc6 --- /dev/null +++ b/testsuite/reftests/textview-border-windows.ui @@ -0,0 +1,20 @@ + + + + + + False + popup + + + 160 + 160 + True + True + word + + + + + + -- 2.30.2